package Telas;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import clientes.ClienteController;
import clientes.exceptions.ClienteInexistenteException;


public class FrPesquisa extends JFrame {

	private JPanel contentPane;
	private JTextField tfPNome;
	private JTextField tfPCpf;
	private JTextField tfPValor;
	private JButton btnLocalizar;
	private JTextField tfPHoraSaida;
	private JTextField tfPHoraEntrada;
	private JTextField tfPTempoTotal;
	private JTextField tfPBairro;
	private JTextField tfPLogradouro;
	private JTextField tfPNum;
	private JTextField tfPComp;
	private JTextField tfPCep;
	private JTextField tfPCidade;
	private JTextField tfPPlaca;
	private JTextField tfPMarca;
	private JTextField tfPModelo;
	private JTextField tfPCor;
	private JTextField tfPAno;
	private JTextField tfPTelefone;
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FrPesquisa frame = new FrPesquisa();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FrPesquisa() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 457);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setBounds(20, 24, 46, 14);
		contentPane.add(lblNome);
		
		tfPNome = new JTextField();
		tfPNome.setHorizontalAlignment(SwingConstants.CENTER);
		tfPNome.setForeground(Color.BLUE);
		tfPNome.setFont(new Font("Verdana", Font.BOLD, 11));
		tfPNome.setBounds(20, 44, 191, 20);
		contentPane.add(tfPNome);
		tfPNome.setColumns(10);
				
		tfPCpf = new JTextField();
		tfPCpf.setHorizontalAlignment(SwingConstants.CENTER);
		tfPCpf.setFont(new Font("Verdana", Font.BOLD, 11));
		tfPCpf.setForeground(Color.BLUE);
		tfPCpf.setBounds(266, 44, 158, 20);
		contentPane.add(tfPCpf);
		tfPCpf.setColumns(10);
		
		tfPValor = new JTextField();
		tfPValor.setFont(new Font("Verdana", Font.BOLD, 12));
		tfPValor.setForeground(Color.RED);
		tfPValor.setHorizontalAlignment(SwingConstants.CENTER);
		tfPValor.setBounds(20, 333, 119, 20);
		contentPane.add(tfPValor);
		tfPValor.setColumns(10);

		tfPBairro = new JTextField();
		tfPBairro.setBounds(329, 161, 95, 20);
		contentPane.add(tfPBairro);
		tfPBairro.setColumns(10);
		
		JLabel lblBairro = new JLabel("Bairro:");
		lblBairro.setBounds(327, 147, 46, 14);
		contentPane.add(lblBairro);
		
		JLabel lblCpf = new JLabel("CPF:");
		lblCpf.setBounds(266, 24, 46, 14);
		contentPane.add(lblCpf);
		
		JLabel lblValor = new JLabel("Valor para Pagamento");
		lblValor.setBounds(21, 319, 108, 14);
		contentPane.add(lblValor);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(10, 75, 414, 2);
		contentPane.add(separator);
		
		JLabel lblHora = new JLabel("H. Entrada:");
		lblHora.setBounds(43, 88, 86, 14);
		contentPane.add(lblHora);
		
		JSeparator separator_1 = new JSeparator();
		separator_1.setBounds(10, 134, 414, 2);
		contentPane.add(separator_1);
		
		JLabel lblSada = new JLabel("H. Sa\u00EDda:");
		lblSada.setBounds(135, 88, 86, 14);
		contentPane.add(lblSada);
		
		tfPHoraSaida = new JTextField();
		tfPHoraSaida.setForeground(Color.BLUE);
		tfPHoraSaida.setFont(new Font("Verdana", Font.BOLD, 11));
		tfPHoraSaida.setHorizontalAlignment(SwingConstants.CENTER);
		tfPHoraSaida.setBounds(135, 103, 79, 20);
		contentPane.add(tfPHoraSaida);
		tfPHoraSaida.setColumns(10);
		
		tfPHoraEntrada = new JTextField();
		tfPHoraEntrada.setForeground(Color.BLUE);
		tfPHoraEntrada.setFont(new Font("Tahoma", Font.BOLD, 11));
		tfPHoraEntrada.setHorizontalAlignment(SwingConstants.CENTER);
		tfPHoraEntrada.setBounds(43, 103, 79, 20);
		contentPane.add(tfPHoraEntrada);
		tfPHoraEntrada.setColumns(10);
		
		JLabel lblTempoTotal = new JLabel("Tempo Total:");
		lblTempoTotal.setBounds(253, 88, 89, 14);
		contentPane.add(lblTempoTotal);
		
		tfPTempoTotal = new JTextField();
		tfPTempoTotal.setFont(new Font("Verdana", Font.BOLD, 11));
		tfPTempoTotal.setForeground(Color.BLUE);
		tfPTempoTotal.setHorizontalAlignment(SwingConstants.CENTER);
		tfPTempoTotal.setBounds(253, 103, 79, 20);
		contentPane.add(tfPTempoTotal);
		tfPTempoTotal.setColumns(10);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			dispose();
			}
		});
		btnSair.setBounds(335, 385, 89, 23);
		contentPane.add(btnSair);
		
		
		JSeparator separator_3 = new JSeparator();
		separator_3.setBounds(10, 237, 414, 14);
		contentPane.add(separator_3);
		
		JLabel lblRua = new JLabel("Rua");
		lblRua.setBounds(20, 147, 46, 14);
		contentPane.add(lblRua);
		
		tfPLogradouro = new JTextField();
		tfPLogradouro.setBounds(20, 161, 169, 20);
		contentPane.add(tfPLogradouro);
		tfPLogradouro.setColumns(10);
		
		JLabel lblN = new JLabel("N\u00BA");
		lblN.setBounds(200, 147, 46, 14);
		contentPane.add(lblN);
		
		tfPNum = new JTextField();
		tfPNum.setBounds(199, 161, 46, 20);
		contentPane.add(tfPNum);
		tfPNum.setColumns(10);
		
		JLabel lblCep = new JLabel("CEP");
		lblCep.setBounds(256, 147, 46, 14);
		contentPane.add(lblCep);
		
		tfPComp = new JTextField();
		tfPComp.setBounds(20, 206, 73, 20);
		contentPane.add(tfPComp);
		tfPComp.setColumns(10);
		
		JLabel lblComplemento = new JLabel("Complemento");
		lblComplemento.setBounds(20, 192, 73, 14);
		contentPane.add(lblComplemento);
		
		tfPCep = new JTextField();
		tfPCep.setBounds(253, 161, 46, 20);
		contentPane.add(tfPCep);
		tfPCep.setColumns(10);
		
		JLabel lblCidade = new JLabel("Cidade");
		lblCidade.setBounds(200, 192, 46, 14);
		contentPane.add(lblCidade);
		
		tfPCidade = new JTextField();
		tfPCidade.setBounds(200, 206, 86, 20);
		contentPane.add(tfPCidade);
		tfPCidade.setColumns(10);
		
		JLabel lblTelefone = new JLabel("Telefone");
		lblTelefone.setBounds(296, 192, 46, 14);
		contentPane.add(lblTelefone);

		tfPTelefone = new JTextField();
		tfPTelefone.setBounds(296, 206, 86, 20);
		contentPane.add(tfPTelefone);
		tfPTelefone.setColumns(10);
		

		JLabel lblPlaca = new JLabel("Placa");
		lblPlaca.setBounds(20, 249, 46, 14);
		contentPane.add(lblPlaca);
		
		tfPPlaca = new JTextField();
		tfPPlaca.setBounds(20, 262, 58, 20);
		contentPane.add(tfPPlaca);
		tfPPlaca.setColumns(10);
		
		JLabel lblMarca = new JLabel("Marca");
		lblMarca.setBounds(84, 249, 46, 14);
		contentPane.add(lblMarca);
		
		tfPMarca = new JTextField();
		tfPMarca.setBounds(84, 262, 89, 20);
		contentPane.add(tfPMarca);
		tfPMarca.setColumns(10);
		
		JLabel lblModelo = new JLabel("Modelo");
		lblModelo.setBounds(183, 249, 46, 14);
		contentPane.add(lblModelo);
		
		tfPModelo = new JTextField();
		tfPModelo.setBounds(183, 262, 79, 20);
		contentPane.add(tfPModelo);
		tfPModelo.setColumns(10);
		
		JLabel lblCor = new JLabel("Cor");
		lblCor.setBounds(272, 249, 46, 14);
		contentPane.add(lblCor);
		
		tfPCor = new JTextField();
		tfPCor.setBounds(272, 262, 77, 20);
		contentPane.add(tfPCor);
		tfPCor.setColumns(10);
		
		JSeparator separator_2 = new JSeparator();
		separator_2.setBounds(10, 300, 414, 5);
		contentPane.add(separator_2);
		
		JSeparator separator_4 = new JSeparator();
		separator_4.setBounds(10, 364, 414, 10);
		contentPane.add(separator_4);
		
		JLabel lblAno = new JLabel("Ano");
		lblAno.setBounds(359, 249, 46, 14);
		contentPane.add(lblAno);
		
		tfPAno = new JTextField();
		tfPAno.setHorizontalAlignment(SwingConstants.CENTER);
		tfPAno.setFont(new Font("Verdana", Font.BOLD, 11));
		tfPAno.setForeground(Color.BLUE);
		tfPAno.setBounds(359, 262, 65, 20);
		contentPane.add(tfPAno);
		tfPAno.setColumns(10);

		btnLocalizar = new JButton("Localizar");
		btnLocalizar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				try{
					new ClienteController().LocalizarCliente(tfPNome, tfPCpf, tfPHoraEntrada, tfPHoraSaida, tfPTempoTotal, tfPLogradouro, tfPNum, tfPComp, tfPBairro, 
							tfPCep,	tfPCidade, tfPTelefone, tfPPlaca, tfPMarca, tfPModelo, tfPCor, tfPAno, tfPValor);										
				} catch (ClienteInexistenteException e) {
					JOptionPane.showMessageDialog(null, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);		
					new ClienteController().LimparTelaPesquisa(tfPNome, tfPCpf, tfPHoraEntrada, tfPHoraSaida, tfPTempoTotal, tfPLogradouro, tfPNum, tfPComp, tfPBairro, 
							tfPCep, tfPCidade, tfPTelefone, tfPPlaca, tfPMarca, tfPModelo, tfPCor, tfPAno, tfPValor);
				}							
			}});
										
		btnLocalizar.setBounds(20, 385, 89, 23);
		contentPane.add(btnLocalizar);

		
		JButton btnExcluir = new JButton("Excluir");
		btnExcluir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				try{
					new ClienteController().ExcluirCliente(tfPNome.getText());
					new ClienteController().LimparTelaPesquisa(tfPNome, tfPCpf, tfPHoraEntrada, tfPHoraSaida, tfPTempoTotal, tfPLogradouro, tfPNum, tfPComp, tfPBairro, 
							tfPCep, tfPCidade, tfPTelefone, tfPPlaca, tfPMarca, tfPModelo, tfPCor, tfPAno, tfPValor);
					JOptionPane.showMessageDialog(null, "Cliente Excluido", "Cadastro", JOptionPane.INFORMATION_MESSAGE);
				} catch (ClienteInexistenteException ex) {
					JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);						
				}							
			}});
		
		btnExcluir.setBounds(236, 385, 89, 23);
		contentPane.add(btnExcluir);
		JButton btnNovaBusca = new JButton("Nova Busca");
		btnNovaBusca.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {				
				new ClienteController().LimparTelaPesquisa(tfPNome, tfPCpf, tfPHoraEntrada, tfPHoraSaida, tfPTempoTotal, tfPLogradouro, tfPNum, tfPComp, tfPBairro, 
						tfPCep, tfPCidade, tfPTelefone, tfPPlaca, tfPMarca, tfPModelo, tfPCor, tfPAno, tfPValor);	
			}
		});
		btnNovaBusca.setBounds(122, 385, 89, 23);
		contentPane.add(btnNovaBusca);				
	}
}
